﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.GUI.LibraryManager.Controls.SubControl;

namespace Com
{
	/// <summary>
	/// Interaction logic for ucAirGlass2.xaml
	/// </summary>
	public partial class ucAirGlass2 : UserControl
	{
        ucAirConditionGlassRadiation gr = new ucAirConditionGlassRadiation();
        ucAirConditionGlassRadiationThroughGlass gs = new ucAirConditionGlassRadiationThroughGlass();
        ucAirConditionImmediateImpact im = new ucAirConditionImmediateImpact();
        ucAirConditionWallGlass wg = new ucAirConditionWallGlass();
        ucAirConditionWindowLigthWell wl = new ucAirConditionWindowLigthWell();
        
   
		public ucAirGlass2()
		{
			this.InitializeComponent();
		}

        private void cbxGlassEcofficient_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dpContainer.Children.Clear();
            //
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                dpContainer.Children.Add(gs);
            }
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                dpContainer.Children.Add(im);
            }
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                dpContainer.Children.Add(gr);
            }
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                dpContainer.Children.Add(wl);
            }
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                dpContainer.Children.Add(wg);
            }

        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Solar radiation
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                gs.saveData();
                enableButtons();
            }
            // Immediate coefficient
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                im.saveData();
                enableButtons();
            }
            // Glass radiation
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                gr.saveData();
                enableButtons();

            }
            // Window and light well
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                wl.saveData();
                enableButtons();
            }
           // Wall glass
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                wg.saveData();
                enableButtons();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                gs.reload();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                im.reload();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                gr.reload();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                wl.reload();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                wg.reload();
                disableButtons();
            }
        }

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                gs.newData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                im.newData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                gr.addNew();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                wl.newData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                wg.newData();
                disableButtons();
            }
        }

        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                gs.copyData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                im.copyData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                gr.copyData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                wl.copyData();
                disableButtons();
            }
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                wg.copyData();
                disableButtons();
            }

        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (cbxGlassEcofficient.SelectedIndex == 0)
            {
                gs.delData();
            }
            if (cbxGlassEcofficient.SelectedIndex == 1)
            {
                im.delData();
            }
            if (cbxGlassEcofficient.SelectedIndex == 2)
            {
                gr.delData();
            }
            if (cbxGlassEcofficient.SelectedIndex == 3)
            {
                wl.delData();
            }
            if (cbxGlassEcofficient.SelectedIndex == 4)
            {
                wg.delData();
            }
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            cbxGlassEcofficient.SelectedIndex = 0;
            enableButtons();
        }

        private void enableButtons()
        {
            btnSave.IsEnabled = false;
            btnCancel.IsEnabled = false;

            btnNew.IsEnabled = true;
            btnCopy.IsEnabled = true;
            btnDelete.IsEnabled = true;
        }
        private void disableButtons()
        {
            btnSave.IsEnabled = true;
            btnCancel.IsEnabled = true;

            btnNew.IsEnabled = false;
            btnCopy.IsEnabled = false;
            btnDelete.IsEnabled = false;
        }
	}
}